﻿using System;
using System.Text;
using System.Web.Mvc;
using Reece.Open.Mvc.Extenders;

namespace Reece.Open.Mvc.Common
{
    public class Form : IDisposable
    {
        private readonly ViewContext _view;

        public Form(ViewContext html, string actionName, string controllerName, string serverBase, FormMethod method)
        {
            _view = html;
            StringBuilder output = new StringBuilder("<form action=\"", 256);
            output.Append(serverBase.AddSlash());
            output.Append(controllerName.AddSlash());
            output.Append(actionName);
            output.Append("\" method=\"");
            output.Append(method.ToString().ToUpper());
            output.Append("\">");
            _view.Writer.WriteLine(output.ToString());
        }

        public void Dispose()
        {
            _view.Writer.WriteLine("</form>");
        }
    }
}
